package com.etl.dataflow.scheduler.timewheel;

import com.etl.dataflow.scheduler.cron.CronExpression;
import lombok.Getter;

import java.util.Date;

/**
 * @author dx
 * @since 2022/6/17
 */
@Getter
public class WheelNode {
    private final WheelTask task;
    private final TimeExpression timeExpression;
    private final CronExpression cronExpression;

    public WheelNode(WheelTask task, TimeExpression timeExpression, CronExpression cronExpression) {
        this.task = task;
        this.timeExpression = timeExpression;
        this.cronExpression = cronExpression;
    }

    public static WheelNode of(WheelTask task, TimeExpression timeExpression, CronExpression cronExpression) {
        return new WheelNode(task, timeExpression, cronExpression);
    }

    public WheelNode createNewInstance(Date date) {
        return new WheelNode(task, TimeExpression.of(date), cronExpression);
    }
}
